/**
 * pinia 组合式 API 写法示例
 */

import { defineStore } from 'pinia'
import { ref, computed } from 'vue'

export const useAboutStore = defineStore(
  'about',
  () => {
    // state
    const sum = ref(1)
    const desc = ref('about')

    // getters
    const upperDesc = computed(() => desc.value.toUpperCase())

    // actions
    const increment = (value: number) => {
      sum.value += value
    }

    // 返回
    return { sum, desc, upperDesc, increment }
  },
  // 数据持久化
  {
    // persist: true,
    persist: {
      paths: ['sum'], // 需要持久化的数据
      // 调整为支持多端的 API
      storage: {
        getItem(key) {
          return uni.getStorageSync(key)
        },
        setItem(key, value) {
          uni.setStorageSync(key, value)
        },
      },
    },
  }
)
